// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.assets.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.assets.controller.request.QueryAssetsInvestmentProjectReq;
import com.liuxinlong.modules.assets.controller.request.UpdateAssetsInvestmentProjectReq;
import com.liuxinlong.modules.assets.service.AssetsInvestmentProjectService;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.request.QueryBaseReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.AssetsInvestmentProject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 固资在线测算项目控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2024-10-18
 */
@RestController
@RequestMapping("/assets/investment-project")
public class AssetsInvestmentProjectController {

    @Autowired
    private AssetsInvestmentProjectService assetsInvestmentProjectService;

    /**
     * 分页查询固资在线测算项目信息列表
     *
     * @param req 请求信息
     * @return 固资在线测算项目信息列表
     */
    @PostMapping("page")
    public BaseResp pageAssetsInvestmentProjectList(@RequestBody QueryAssetsInvestmentProjectReq req) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startNum", req.getStartNum());
        queryMap.put("pageSize", req.getPageSize());
        queryMap.put("greenNo", req.getGreenNo());
        queryMap.put("projectName", req.getProjectName());
        queryMap.put("approveStartTime", req.getApproveStartTime());
        queryMap.put("approveEndTime", req.getApproveEndTime());
        queryMap.put("marketStartTime", req.getMarketStartTime());
        queryMap.put("marketEndTime", req.getMarketEndTime());
        List<Map<String, Object>> dataList = assetsInvestmentProjectService.pageAssetsInvestmentProjectInfo(queryMap);
        int totalNum = assetsInvestmentProjectService.getAssetsInvestmentProjectCount(queryMap);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("分页查询固资在线测算信息成功");
        resp.setDataList(dataList);
        resp.setTotalNum(totalNum);
        return resp;
    }

    /**
     * 获取固资在线测算项目信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("detail")
    @LogAnnotation(value = "获取固资在线测算项目信息", business = LogBusinessConstants.ASSETS_INVESTMENT_PROJECT, operateType = LogOperateConstants.OPERATE_ADD)
    public BaseResp getAssetsInvestmentDetail(@RequestBody QueryBaseReq req) {
        Map<String,Object> dataMap = assetsInvestmentProjectService.getAssetsInvestmentDetail(req.getId());
        BaseResp resp = new BaseResp();
        resp.setDataMap(dataMap);
        resp.setRetMessage("获取固资在线测算项目信息成功");
        return resp;
    }

    /**
     * 新增固资在线测算项目信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("add")
    @LogAnnotation(value = "新增固资在线测算项目信息", business = LogBusinessConstants.ASSETS_INVESTMENT_PROJECT, operateType = LogOperateConstants.OPERATE_ADD)
    public BaseResp addAssetsInvestmentProjectInfo(@RequestBody UpdateAssetsInvestmentProjectReq req) {
        AssetsInvestmentProject assetsInvestmentProject = new AssetsInvestmentProject();
        assetsInvestmentProject.setInvestmentId(req.getInvestmentId());
        assetsInvestmentProject.setPlant(req.getPlant());
        assetsInvestmentProject.setApproveTime(req.getApproveTime());
        assetsInvestmentProject.setRemark(req.getProjectRemark());
        assetsInvestmentProject.setGreenNo(req.getGreenNo());
        assetsInvestmentProjectService.addAssetsInvestmentProject(assetsInvestmentProject);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("新增固资在线测算项目信息成功");
        return resp;
    }

    /**
     * 修改固资在线测算项目信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("update")
    @LogAnnotation(value = "修改固资在线测算项目信息", business = LogBusinessConstants.ASSETS_INVESTMENT_PROJECT, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateAssetsInvestmentProjectInfo(@RequestBody UpdateAssetsInvestmentProjectReq req) {
        AssetsInvestmentProject assetsInvestmentProject = new AssetsInvestmentProject();
        assetsInvestmentProject.setId(req.getId());
        assetsInvestmentProject.setInvestmentId(req.getInvestmentId());
        assetsInvestmentProject.setPlant(req.getPlant());
        assetsInvestmentProject.setApproveTime(req.getApproveTime());
        assetsInvestmentProject.setRemark(req.getProjectRemark());
        assetsInvestmentProject.setGreenNo(req.getGreenNo());
        assetsInvestmentProjectService.updateAssetsInvestmentProject(assetsInvestmentProject);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改固资项目信息成功");
        return resp;
    }

    /**
     * 删除固资在线测算项目信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("delete")
    @LogAnnotation(value = "删除固资在线测算项目信息", business = LogBusinessConstants.ASSETS_INVESTMENT_PROJECT, operateType = LogOperateConstants.OPERATE_DELETE)
    public BaseResp deleteAssetsInvestmentProjectInfo(@RequestBody BaseDeleteReq req) {
        assetsInvestmentProjectService.deleteAssetsInvestmentProject(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("删除固资在线测算项目信息成功");
        return resp;
    }
}
